package com.ezops.poc.processor;

import java.util.ArrayList;
import java.util.List;

import org.apache.camel.Exchange;
import org.springframework.stereotype.Component;

import com.ezops.poc.bo.EzopsOTEquityModel;
import com.ezops.trade.processing.partners.orchestrade.equity.OrchesTradeEquityModel;
@Component(value="tradeSplitter")
public class TradeSplitter {

	public  List<String> extractTokens(final Exchange exchange) {
		List splittedOnType = new ArrayList<>();

		List<OrchesTradeEquityModel> validTrades = new ArrayList<>();
		List<EzopsOTEquityModel> invalidTrades = new ArrayList<>();

		List aggregatedTrades = exchange.getIn().getBody(List.class);

		for (Object trade : aggregatedTrades) {
			if (trade instanceof EzopsOTEquityModel) {
				invalidTrades.add((EzopsOTEquityModel) trade);
			} else {
				validTrades.add((OrchesTradeEquityModel) trade);
			}
		}

		splittedOnType.add(validTrades);
		splittedOnType.add(invalidTrades);
		return splittedOnType;
	}
}
